<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<form ng-submit="$ctrl.search()" name="logsFiltersForm">
  <div layout-gt-sm="row">
    <md-input-container class="md-block" flex-gt-sm flex="20">
      <label>Request ID</label>
      <input ng-model="$ctrl.filters.id">
    </md-input-container>
    <md-input-container class="md-block" flex-gt-sm flex="20">
      <label>Transaction ID</label>
      <input ng-model="$ctrl.filters.transaction">
    </md-input-container>
    <md-input-container class="md-block" flex-gt-sm flex="20">
      <label>Methods</label>
      <md-select ng-model="$ctrl.filters.method" placeholder="Methods" multiple>
        <md-option ng-value="key" ng-repeat="(key, value) in $ctrl.methods">{{ value }}</md-option>
      </md-select>
    </md-input-container>
    <md-input-container class="md-block" flex-gt-sm flex="20">
      <label>Path</label>
      <input ng-model="$ctrl.filters.uri">
    </md-input-container>
    <md-input-container class="md-block" flex-gt-sm flex="20">
      <label>Response times</label>
      <md-select ng-model="$ctrl.filters.responseTime" placeholder="Response times" multiple>
        <md-option ng-value="key" ng-repeat="(key, value) in $ctrl.responseTimes">{{ value }}</md-option>
      </md-select>
    </md-input-container>
    <md-input-container class="md-block" flex-gt-sm flex="20">
      <label>HTTP Status</label>
      <md-select ng-model="$ctrl.filters.status" placeholder="HTTP Status" multiple>
        <md-option ng-value="key" ng-repeat="(key, value) in $ctrl.httpStatus">{{key}} - {{ value }}</md-option>
      </md-select>
    </md-input-container>
  </div>
  <div layout-gt-sm="row">
    <md-input-container class="md-block" flex-gt-sm flex="20" ng-if="$ctrl.context === 'api' || $ctrl.context === 'platform'">
      <label>Applications</label>
      <md-select ng-model="$ctrl.filters.application" placeholder="Application" multiple>
        <md-option ng-value="app.id" ng-repeat="app in $ctrl.metadata.applications">{{app.name}}</md-option>
      </md-select>
    </md-input-container>
    <md-input-container class="md-block" flex-gt-sm flex="20" ng-if="$ctrl.context === 'application' || $ctrl.context === 'platform'">
      <label>Apis</label>
      <md-select ng-model="$ctrl.filters.api" placeholder="API" multiple>
        <md-option ng-value="api.id" ng-repeat="api in $ctrl.metadata.apis">{{api.name}}</md-option>
      </md-select>
    </md-input-container>
    <md-input-container class="md-block" flex-gt-sm flex="20" ng-if="$ctrl.context === 'api'">
      <label>Plans</label>
      <md-select ng-model="$ctrl.filters.plan" placeholder="Plan" multiple>
        <md-option ng-value="plan.id" ng-repeat="plan in $ctrl.metadata.plans">{{plan.name}}</md-option>
      </md-select>
    </md-input-container>
    <md-input-container class="md-block" flex-gt-sm flex="20" ng-if="$ctrl.metadata.tenants.length > 0">
      <label>Tenants</label>
      <md-select ng-model="$ctrl.filters.tenant" placeholder="Tenant" multiple>
        <md-option ng-value="tenant.id" ng-repeat="tenant in $ctrl.metadata.tenants">{{tenant.name}}</md-option>
      </md-select>
    </md-input-container>
    <md-input-container ng-if="$ctrl.$state.params['apiId']">
      <md-select ng-model="$ctrl.displayMode" ng-change="$ctrl.updateDisplayMode()" placeholder="Display mode">
        <md-option ng-repeat="displayMode in $ctrl.displayModes" ng-value="displayMode">
          {{displayMode.label}}
        </md-option>
      </md-select>
    </md-input-container>
    <md-input-container class="md-block" flex-gt-sm>
      <label>Search in payloads</label>
      <input ng-model="$ctrl.filters.body">
    </md-input-container>
    <md-input-container class="md-block" flex-gt-sm ng-if="$ctrl.context != 'platform'">
      <label>Endpoint</label>
      <input ng-model="$ctrl.filters.endpoint">
    </md-input-container>
    <md-input-container class="md-block" flex-gt-sm ng-if="$ctrl.context === 'api'">
      <label>Remote Address</label>
      <input ng-model="$ctrl.filters['remote-address']">
    </md-input-container>
    <div>
      <md-button type="submit" class="md-raised md-primary">
        Search
      </md-button>
      <md-button type="button" class="md-flat" ng-click="$ctrl.clearFilters()" ng-disabled="!$ctrl.hasFilters()">
        Clear filters
      </md-button>
    </div>
  </div>
</form>
